<template>
	<view class='u-p-20'>
		<view class="u-p-20 u-b-r-10 bg_FFFFFF ">
			<view class="u-flex" style="padding: 30rpx 0;border-bottom: 1rpx solid #E1E1E1FF;">
				<view class="u-w-680">
					<u-input type='password' placeholder='请输入旧密码' v-model='oldpass' maxlength='6'></u-input>
				</view>
			</view>
			<view class="u-flex" style="padding: 30rpx 0;border-bottom: 1rpx solid #E1E1E1FF;">
				<view class="u-w-680">
					<u-input type='password' placeholder='请设置6位密码' v-model='password' maxlength='6'></u-input>
				</view>
			</view>
			<view class="u-flex" style="padding: 30rpx 0;border-bottom: 1rpx solid #E1E1E1FF;">
				<view class="u-w-680">
					<u-input type='password' placeholder='确认密码' v-model='passwords' maxlength='6'></u-input>
				</view>
			</view>
		</view>
		<view class="u-w-710 u-h-100 u-l-h-100 u-text-center u-fix u-b-50  u-b-r-13 cl_FFF"
			style="background: linear-gradient(-64deg, #FF382C, #FF633F);" @click="add">提交</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				num: 1,
				time: 59,
				asd: 1,
				oldpass: '',
				password: '',
				passwords: '',
				userinfo: '',
				code: ''
			}
		},
		onLoad(obj) {
			this.userinfo = uni.getStorageSync("userinfo")
			this.masage()

		},
		methods: {
			masage() {
				this.$api.sed_code({
					mobile: this.userinfo.mobile,
					type: 'modify',
					uuid: '', //this.uuid,
					captcha: '', //this.model.captcha,
					guard: 'member'
				}, res => {
					console.log(res);
					if (res.data.code == 1) {
						let arr = setInterval(() => {
							if (this.time > 1) {
								this.time--
							} else {
								clearInterval(arr)
								this.num = 2
							}
						}, 1000)
					}
				})

			},
			// 点击重新获取
			begins() {
				this.time = 1
				this.time = 59
				this.massage()
			},

			change(e) {
				console.log('内容改变，当前值为：' + e);
			},
			finish(e) {
				console.log('输入结束，当前值为：' + e);
				if (e.length == 6) {
					this.asd = 2
					this.code = e
				}
			},
			add() {
				if (this.oldpass.trim() == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入旧密码'
					})
				} else if (this.password.trim() == '') {
					uni.showToast({
						icon: 'none',
						title: '请输入密码'
					})
				} else if (this.password != this.passwords) {
					uni.showToast({
						icon: 'none',
						title: '两次密码不一致'
					})
				} else {
					this.$api.chnage_my_login_password({
						oldpass: this.oldpass,
						loginpass: this.password,
						quepass: this.passwords
					}, res => {
						if(res.data.code==1){
							uni.showToast({
								icon:'none',
								title:'修改成功，请重新登录'
							})
							
							setTimeout(()=>{
								uni.reLaunch({
								url:'/pages/login/login'
							})
							},500)
							this.get_my_massage()
						}else{
							uni.showToast({
								icon:'none',
								title:res.data.msg
							})
						}
					})
				}

			},
			// 个人资料更新
			async get_my_massage() {
				await this.$api.get_my_massage({}, res => {
					if (res.data.code == 1) {
						uni.setStorageSync('userinfo', res.data.data.data)
					}
				})
			},
		}
	}
</script>

<style scoped>
	page {
		background: #F5F5F5FF !important;
	}
</style>
